<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        性别：{{sex|formatterSex}}
    </div>
    <div id="vm">
        性别：{{sex|formatterSex}}
    </div>
    <script src="../vue.js"></script>
    <script>
        //全局过滤器
        Vue.filter('formatterSex',function(val){
            return val==1?'男':val==2?'女':'未知';
        })
        new Vue({
            el:'#app',
            data () {
                return {
                    sex:1,
                }
            }
        })
        new Vue({
            el:'#vm',
            data () {
                return {
                    sex:2,
                }
            }
        })
    </script>
</body>
</html>